<template>
	<view>
		<u-toast ref="uToast" />
		<view class="center">
			<view class="icon">
				<view class="image_icon">
					<image slot="icon" class="box_icon" :src="list.typeIcon"></image>
				</view>
				<view class="icon_text">
					<text>{{list.billType}}</text>
				</view>
			</view>
			
			<view class="money">
				<text v-if="list.state == 1">-{{list.money}}</text>
				<text v-else>+{{list.money}}</text>
			</view>
		</view>
		<view class="info">
			<view>
				<view class="left_info">记录时间</view>
				<view class="left_info" v-if="list.accountName">账户</view>
				<view class="left_info">备注</view>
			</view>
			<view>
				<view class="right_info"><text>{{list.billDate}}&nbsp;&nbsp;{{list.billTime}}</text></view>
				<view class="right_info" v-if="list.accountName"><text>{{list.accountName}}</text></view>
				<view class="right_info"><text class="tar">{{list.remarks}}</text></view>
			</view>
		</view>
		<view class="divider">
			<u-divider lineColor="#82848a" :dot="true"></u-divider>
		</view>
		<view class="button">
			<view class="left_button">
				<u-button type="error" icon="trash" text="删除" size="normal" plain @click="deleteDetail()"></u-button>
			</view>
			<view class="right_button">
				<u-button type="primary" icon="edit-pen" text="编辑" size="normal" plain @click="getAddDetail()"></u-button>
			</view>
		</view>
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: {}
			}
		},
		onLoad(options) {
			this.list = JSON.parse(options.data)
			console.log(this.list)
		},
		methods: {
			getAddDetail (){
				//submitType=1代表编辑
				let data = {
					"submitType": 1,
					"billId": this.list.billId,
					"state": this.list.state,
					"money": this.list.money,
					"billDate": this.list.billDate,
					"remarks": this.list.remarks,
					"accountName": this.list.accountName
				}
				uni.navigateTo({
					url: '/pages/adddetail/adddetail?data='+JSON.stringify(data)
				})
			},
			deleteDetail() {
				let params = {
					"userId": uni.getStorageSync('userId'),
					"billId": this.list.billId
				}
				const _this = this
				uni.request({
					header: {
						  'Content-Type': 'application/x-www-form-urlencoded',
						  'token': uni.getStorageSync('token')
					   }, 
					url: this.$USER_AVATOR_URL.USER_AVATOR_URL+"/detail/deletebill",
					method: 'POST',
					data: params,
					success(res) {
						console.log(res)
						if (res.data.code == 200) {
							_this.$refs.uToast.show({
								type: 'success',
								title: '删除成功',
								message: res.data.errorMessage,
								duration: 700,
								complete() {
									uni.switchTab({
										url: '/pages/detail/detail',
										success: (res) => {
											let page = getCurrentPages().pop();
											if (page == undefined || page == null) return;
											page.onLoad();
										}
										
									})
								},
								
							})
						}else{
							_this.$refs.uToast.show({
								type: 'error',
								title: '删除失败',
								message: res.data.errorMessage,
								duration: 1000,
							})
						}
					}
				})
			},
			
		}
	}
</script>

<style>
	.center {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;

	}
	.money {
		font-size: 70rpx;
		margin-top: 20rpx;
		margin-bottom: 30rpx;
	}
	
	.info {
		height: 250rpx;
		display: flex;
		flex-wrap: wrap;
		justify-content: center;
	}
	
	.left_info {
		width: 150rpx;
		height: 80rpx;
		color: #82848a;
	}
	.right_info {
		width: 400rpx;
		height: 80rpx;
		flex-wrap: wrap;
		word-break: break-all;
		white-space: pre-line;
	}
	.divider {
		padding-left: 25rpx;
		padding-right: 25rpx;
	}
	.button {
		display: flex;
		justify-content: center;
		align-items: center;
	}
	.left_button {
		width: 200rpx;
		height: 100rpx;
		margin: 50rpx;
	}
	
	.right_button {
		width: 200rpx;
		height: 100rpx;
		margin: 50rpx;
	}
	.icon {
		height: 60rpx;
		display: flex;
		flex-wrap: wrap;
		margin-top: 100rpx;
	}
	.image_icon {
		height: 60rpx;
		width: 60rpx;
		display:flex;
		justify-content:center;
		align-items:center;
		
		background-color: #007AFF;
		border-radius: 100%;
		box-sizing: border-box;
		-webkit-box-sizing: border-box;
		-moz-box-sizing: border-box; 
	}
	.box_icon {
		height: 45rpx;
		width: 45rpx;
		
	}
	
	.icon_text {
		height: 60rpx;
		width: 100rpx;
		font-size: 40rpx;
		display:flex;
		align-items:center;
		margin-left: 20rpx;
	}
</style>
